﻿﻿﻿<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ include file="/common/include/page.jsp"%>


  <c:set value="${requestScope.response.list0 }" var="menuList1" />
	<c:set value="${requestScope.response.list1 }" var="menuList2" />
	<c:set value="${requestScope.response.list2 }" var="menuList3" /> 
<c:set value="${requestScope.roleResponse.data.one }" var="roleTemp" />
<!DOCTYPE HTML>
<html>
<head>
<%@ include file="/common/include/title.jsp"%>
<link rel="stylesheet"
	href="${rootPath }/common/resource/H-ui.admin/lib/zTree/v3/css/zTreeStyle/zTreeStyle.css"
	type="text/css">
<title>菜单树形结构 - 用户中心</title>
</head>
<body>
	<nav class="breadcrumb">
		<i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span>
		权限管理
		<c:choose>
			<c:when test="${param.roleId != null && param.roleId != ''}">
				<span class="c-gray en">&gt;</span> 角色授权
				
				</c:when>
			<c:otherwise>
				<span class="c-gray en">&gt;</span> 菜单列表(树形) 
				</c:otherwise>
		</c:choose>
			<a class="btn btn-success radius r" style="line-height: 1.6em; margin-top: 3px"href="javascript:location.replace(location.href);" title="刷新">
			<i class="Hui-iconfont">&#xe68f;</i>
			</a>
	</nav>
	<c:if test="${param.roleId != null && param.roleId != ''}">
			角色:${roleTemp.name}
		</c:if>
	<c:forEach items="${requestScope.response}" var="map" varStatus="stat">
		<%-- <c:set value="${map.value}" var="1" /> --%>
 		<div style="float:left">
			<table class="table">
				<a class="showResult"></a>
				<tr>
					<td width="200" class="va-t"><input type="hidden" name="roleId"
						value="${param.roleId }">
						<ul id="treeDemo${stat.count}"  class="ztree"></ul> 
						<c:if test="${param.roleId != null && param.roleId != ''&&stat.count==1}">
							<a class="btn btn-primary radius" onclick="return roleSubmit()">
								<i class="Hui-iconfont">&#xe632;</i> 提交
							</a>
						</c:if>
					</td>
				</tr>
			</table>
		</div>
 	</c:forEach> 	
	
	
	<%-- <!-- 中间 -->
	<div style="float:left">
		<table class="table">
			<a class="showResult"></a>
			<tr>
				<td width="200" class="va-t"><input type="hidden" name="roleId"
					value="${param.roleId }">

					<ul id="treeDemo1" class="ztree"></ul> <c:if
						test="${param.roleId != null && param.roleId != ''}">
						<!-- <a class="btn btn-primary radius" onclick="return roleSubmit()">
							<i class="Hui-iconfont">&#xe632;</i> 提交
						</a> -->
					</c:if>
				</td>
			</tr>
		</table>
	</div>
	<!-- 右边 -->
	<div style="float:left">
		<table class="table">
			<a class="showResult"></a>
			<tr>
				<td width="200" class="va-t"><input type="hidden" name="roleId"
					value="${param.roleId }">

					<ul id="treeDemo2" class="ztree"></ul> <c:if
						test="${param.roleId != null && param.roleId != ''}">
						<!-- <a class="btn btn-primary radius" onclick="return roleSubmit()">
							<i class="Hui-iconfont">&#xe632;</i> 提交
						</a> -->
					</c:if>
				</td>
			</tr>
		</table>
	</div> --%>
	<%@ include file="/common/include/footer.jsp"%>
	<!--请在下方写此页面业务相关的脚本-->
	<script type="text/javascript"
		src="${rootPath }/common/resource/H-ui.admin/lib/zTree/v3/js/jquery.ztree.all-3.5.min.js"></script>
	<script type="text/javascript">
	
			var setting = {
				view : {
					dblClickExpand : true,
					showLine : true,
					selectedMulti : true
				},
				data : {
					simpleData : {
						enable : true,
						idKey : "id",
						pIdKey : "pId",
						rootPId : ""
					}
				},
				<c:if test="${param.roleId != null && param.roleId != ''}">
					check: {
						enable: true,
						chkStyle: "checkbox",
					},
				</c:if>
			};
			 <c:forEach items="${requestScope.response}" var="map" varStatus="status">
				/* <c:set value="${map.value}" var="1" /> */
			 var ${map.key} = [
				<c:forEach items="${map.value}" var="pojoTemp" varStatus="stat">
					{
						id : ${pojoTemp.id },
						pId : ${pojoTemp.parentId },
						name : "${pojoTemp.name }",
						open : false,
						<c:if test="${param.roleId != null && param.roleId != ''}">
							checked : ${pojoTemp.roleMenuFlag},
						</c:if>
					},
				</c:forEach>
			];
			 var zTree${status.count}  ; 
				$(document).ready(function() {
					var t = $("#treeDemo${status.count}");
					zTree${status.count} = $.fn.zTree.init(t, setting, ${map.key});
				});
			 
			</c:forEach> 
			/* var zNodes = [
				<c:forEach items="${menuList1 }" var="pojoTemp" varStatus="stat">
					{
						id : ${pojoTemp.id },
						pId : ${pojoTemp.parentId },
						name : "${pojoTemp.name }",
						open : false,
						<c:if test="${param.roleId != null && param.roleId != ''}">
							checked : ${pojoTemp.roleMenuFlag},
						</c:if>
					},
				</c:forEach>
			];
			var zNodes1 = [
				<c:forEach items="${menuList2 }" var="pojoTemp" varStatus="stat">
					{
						id : ${pojoTemp.id },
						pId : ${pojoTemp.parentId },
						name : "${pojoTemp.name }",
						open : false,
						<c:if test="${param.roleId != null && param.roleId != ''}">
							checked : ${pojoTemp.roleMenuFlag},
						</c:if>
					},
				</c:forEach>
			];
			var zNodes2 = [
				<c:forEach items="${menuList3 }" var="pojoTemp" varStatus="stat">
					{
						id : ${pojoTemp.id },
						pId : ${pojoTemp.parentId },
						name : "${pojoTemp.name }",
						open : false,
						<c:if test="${param.roleId != null && param.roleId != ''}">
							checked : ${pojoTemp.roleMenuFlag},
						</c:if>
					},
				</c:forEach>
			];
			 */
			
			/* var zTree  ; 
			
			$(document).ready(function() {
				var t = $("#treeDemo");
				zTree = $.fn.zTree.init(t, setting, zNodes);
			});
			
			
			var zTree1 ;
			$(document).ready(function() {
				var t = $("#treeDemo1");
				zTree1 = $.fn.zTree.init(t, setting, zNodes1);
			});
			
			
			var zTree2 ;
			$(document).ready(function() {
				var t = $("#treeDemo2");
				zTree2 = $.fn.zTree.init(t, setting, zNodes2);
			}); */
			/**
				获取选中的节点,
				然后提交
			*/
			function roleSubmit()
			{
				var queryStr = "roleId=${param.roleId}&";
				 <c:forEach items="${requestScope.response}" var="map" varStatus="stat">
					/* <c:set value="${map.value}" var="1" /> */
				var nodes${stat.count} = zTree${stat.count}.getCheckedNodes(true);
				for(var i = 0 ;i < nodes${stat.count}.length; i ++)
				{
					var tempObj = nodes${stat.count}[i] ;
					queryStr += "menuId=" + tempObj.id + "&";
				}				 
				</c:forEach> 
				
				/* var nodes1 = zTree1.getCheckedNodes(true);
				var nodes2 = zTree2.getCheckedNodes(true);
				for(var i = 0 ;i < nodes.length; i ++)
				{
					var tempObj = nodes[i] ;
					queryStr += "menuId=" + tempObj.id + "&";
				}
				for(var i = 0 ;i < nodes1.length; i ++)
				{
					var tempObj = nodes1[i] ;
					queryStr += "menuId=" + tempObj.id + "&";
				}
				for(var i = 0 ;i < nodes2.length; i ++)
				{
					var tempObj = nodes2[i] ;
					queryStr += "menuId=" + tempObj.id + "&";
				} */
				$.ajax({
					type: 'post',
					url:'${rootPath}/back/rbac/roleMenuTreeInsertSubmit.htm',
					data: queryStr ,
					 beforeSend: function () {
						 $('.showResult').append("<div class='center-in-center'><img src='${rootPath }/common/resource/H-ui.admin/static/h-ui.admin/images/loading.gif' /><div>");
					 	$('.btn-primary').removeAttr("onclick");  
					 },
					success: function(data){
						layer.msg(data.info,{icon:1,time:5000},function()
						{
							if(data.code == '0')
							{
								var index = parent.layer.getFrameIndex(window.name);
								parent.$('.btn-success').click();
								parent.layer.close(index);
							}
						});
					},
					complete: function () {
						 $('.showResult').remove();
						 $('.btn-primary').attr("onclick","return roleSubmit()");
					   },
					error:function(XMLHttpRequest){
						layer.msg(data.info,{icon:1,time:5000});
					},
					dataType:"json"
				});
			}
		</script>
</body>
</html>